package com.boot2.core.web;

import com.boot2.core.utils.ServletUtil;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.servlet.HandlerMapping;

import javax.servlet.http.HttpServletRequest;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangweilin
 * @Description: 拓展RestTemplate, 如果方法名不带"Form"字样，除了get形式，传参都是以json方式，被调用方均以@RequestBody形式接收，当方法名是有"Form"字样时，表示按表单形式请求
 * 目前还缺少一个组合，即带返回头
 * @date 2020/5/11
 */
public class MyRestTemplate extends AbstractRestTemplate {

    //////======================================================================================================
    //////=====================                                                           ======================
    //////=====================  以下为默认的json参数方式的请求,如果是post，接收方要以@RequestBody形式接收  ======================
    //////=====================                                                           ======================
    //////======================================================================================================

    //====get===========================================================================
    @Nullable
    public <T> T getForObject(String url, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            //是刷token的标志为参数中有refreshToken参数
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
        }
        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
    }

    @Nullable
    public <T> T getForObject(String url, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        //是刷token的标志为参数中有refreshToken参数
        Map<String, Object> map = null;
        if (null != request1) {
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, map);
    }

//    @Nullable
//    public <T> T getForObject(URI url,Map<String,Object> paramMap, Class<T> responseType) throws RestClientException {
//        return super.getForObject(url, responseType);
//    }

    public <T> ResponseEntity<T> getForEntity(String url, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            //是刷token的标志为参数中有refreshToken参数
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
        }
        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
    }

    public <T> ResponseEntity<T> getForEntity(String url, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            //是刷token的标志为参数中有refreshToken参数
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, map);
    }

//    @Override
//    public <T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException {
//        return super.getForEntity(url, responseType);
//    }


    // ============DELETE======================
    public void delete(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
        }
        super.delete(ServletUtil.addParamter(url, paramMap), uriVariables);
    }

    public void delete(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        super.delete(ServletUtil.addParamter(url, paramMap), map);
    }

    public String deleteWithResponse(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
        }
        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, String.class, uriVariables);
    }

    public Map<String, Object> deleteWithMapResponse(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
        }
        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, uriVariables);
    }

    public String deleteWithResponse(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, String.class, map);
    }

    public Map<String, Object> deleteWithMapResponse(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, map);
    }

//    @Override
//    public void delete(URI url) throws RestClientException {
//        super.delete(url);
//    }

    //=====post=============================================================================
    @Override
    @Nullable
    public URI postForLocation(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.postForLocation(url, request, uriVariables);
    }

    @Override
    @Nullable
    public URI postForLocation(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return super.postForLocation(url, request, map);
    }

    @Override
    @Nullable
    public URI postForLocation(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.postForLocation(url, request);
    }

    @Override
    @Nullable
    public <T> T postForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.postForObject(url, request, responseType, uriVariables);
    }

    @Override
    @Nullable
    public <T> T postForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return super.postForObject(url, request, responseType, map);
    }

    @Override
    @Nullable
    public <T> T postForObject(URI url, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.postForObject(url, request, responseType);
    }

    @Override
    public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request,
                                               Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.postForEntity(url, request, responseType, uriVariables);
    }

    @Override
    public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request,
                                               Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return super.postForEntity(url, request, responseType, map);
    }

    @Override
    public <T> ResponseEntity<T> postForEntity(URI url, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.postForEntity(url, request, responseType);
    }


    // ==========PUT========================================

    @Override
    public void put(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        super.put(url, request, uriVariables);
    }

    @Override
    public void put(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        super.put(url, request, map);
    }

    @Override
    public void put(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        super.put(url, request);
    }

    public String putWithResponse(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return jsonExchange(url, HttpMethod.PUT, request, String.class, uriVariables);

//        HttpEntity<Object> entity = getHttpEntity(request);
//        ResponseEntity<String> resultEntity = super.exchange(url,  HttpMethod.PUT, entity,  String.class, uriVariables);
//        return resultEntity.getBody();
    }

    public String putWithResponse(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return jsonExchange(url, HttpMethod.PUT, request, String.class, map);
    }

    public String putWithResponse(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return jsonExchange(url, HttpMethod.PUT, request, String.class);
    }

    public Map<String, Object> putWithMapResponse(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return jsonExchange(url, HttpMethod.PUT, request, Map.class, uriVariables);
    }

    public Map<String, Object> putWithMapResponse(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return jsonExchange(url, HttpMethod.PUT, request, Map.class, map);
    }

    public Map<String, Object> putWithMapResponse(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return jsonExchange(url, HttpMethod.PUT, request, Map.class);
    }

    // ==============PATCH==========================================

    @Override
    @Nullable
    public <T> T patchForObject(String url, @Nullable Object request, Class<T> responseType,
                                Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.patchForObject(url, request, responseType, uriVariables);
    }

    @Override
    @Nullable
    public <T> T patchForObject(String url, @Nullable Object request, Class<T> responseType,
                                Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return super.patchForObject(url, request, responseType, map);
    }

    @Override
    @Nullable
    public <T> T patchForObject(URI url, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        return super.patchForObject(url, request, responseType);
    }

    //==============以下为去掉class参数的重载==============

    //====get===========================================================================
    @Nullable
    public String getForObject(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        return getForObject(url, paramMap, String.class, uriVariables);
    }

    @Nullable
    public String getForObject(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return getForObject(url, paramMap, String.class, map);
    }

    @Nullable
    public Map<String, Object> getForMap(String url) throws RestClientException {
        return getForMap(url, new HashMap<String, Object>(), new Object());
    }

    @Nullable
    public Map<String, Object> getForMap(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        return getForObject(url, paramMap, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> getForMap(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return getForObject(url, paramMap, Map.class, map);
    }

//    @Nullable
//    public <T> T getForObject(URI url,Map<String,Object> paramMap, Class<T> responseType) throws RestClientException {
//        return super.getForObject(url, responseType);
//    }


    //=======post==========
    @Nullable
    public String postForObject(String url, @Nullable Object request,
                                Object... uriVariables) throws RestClientException {
        return postForObject(url, request, String.class, uriVariables);
    }

    @Nullable
    public String postForObject(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postForObject(url, request, String.class, map);
    }

    @Nullable
    public String postForObject(URI url, @Nullable Object request) throws RestClientException {
        return postForObject(url, request, String.class);
    }

    @Nullable
    public Map<String, Object> postForMap(String url, @Nullable Object request,
                                          Object... uriVariables) throws RestClientException {
        return postForObject(url, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> postForMap(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postForObject(url, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> postForMap(URI url, @Nullable Object request) throws RestClientException {
        return postForObject(url, request, Map.class);
    }


    // ==============PATCH==========================================

    @Nullable
    public String patchForObject(String url, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchForObject(url, request, String.class, uriVariables);
    }

    @Nullable
    public String patchForObject(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchForObject(url, request, String.class, map);
    }

    @Nullable
    public String patchForObject(URI url, @Nullable Object request) throws RestClientException {
        return patchForObject(url, request, String.class);
    }

    @Nullable
    public Map<String, Object> patchForMap(String url, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchForObject(url, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> patchForMap(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchForObject(url, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> patchForMap(URI url, @Nullable Object request) throws RestClientException {
        return patchForObject(url, request, Map.class);
    }


    //////======================================================================================================
    //////=====================                                                           ======================
    //////=====================            以上为不携带header的请求                       ======================
    //////=====================            以下为携带header的请求                       ======================
    //////=====================                                                           ======================
    //////======================================================================================================


    //====get===========================================================================
    @Nullable
    public <T> T getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        //是刷token的标志为参数中有refreshToken参数
        if (null != request1) {
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
        }
//        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);

        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType);
        return responseEntity.getBody();
    }

    @Nullable
    public <T> T getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        //是刷token的标志为参数中有refreshToken参数
        Map<String, Object> map = null;
        if (null != request1) {
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, map);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType, map);
        return responseEntity.getBody();
    }


    public <T> ResponseEntity<T> getForEntityWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        //是刷token的标志为参数中有refreshToken参数
        if (null != request1) {
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
        }
//        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        return super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType, uriVariables);
    }

    public <T> ResponseEntity<T> getForEntityWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        //是刷token的标志为参数中有refreshToken参数
        Map<String, Object> map = null;
        if (null != request1) {
            if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
                request1.setAttribute(refreshTokenParamMapKey, paramMap);
            } else {
                request1.setAttribute(paramMapKey, paramMap);
            }
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, map);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        return super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType, map);
    }


    // ============DELETE======================
    public <T> T deleteWithHeaderAndResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
        }
//        super.delete(ServletUtil.addParamter(url, paramMap), uriVariables);

        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, responseType, uriVariables);
        return responseEntity.getBody();
    }

    public <T> T deleteWithHeaderAndResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        super.delete(ServletUtil.addParamter(url, paramMap), map);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, responseType, map);
        return responseEntity.getBody();
    }

    public Map<String, Object> deleteWithHeaderAndMapResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
        }
//        return exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, uriVariables);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<Map> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, Map.class, uriVariables);
        return responseEntity.getBody();
    }

    public String deleteWithHeaderAndResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        return exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, String.class, map);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<String> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, String.class, map);
        return responseEntity.getBody();
    }

    public Map<String, Object> deleteWithHeaderAndMapResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, paramMap);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        return exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, map);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
        ResponseEntity<Map> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, Map.class, map);
        return responseEntity.getBody();
    }

//    @Override
//    public void delete(URI url) throws RestClientException {
//        super.delete(url);
//    }

    //=====post=============================================================================
    @Nullable
    public URI postForLocationWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForLocation(url, postEntity, uriVariables);
    }

    @Nullable
    public URI postForLocationWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForLocation(url, postEntity, map);
    }

    @Nullable
    public URI postForLocationWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForLocation(url, postEntity);
    }

    @Nullable
    public <T> T postForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }

        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForObject(url, postEntity, responseType, uriVariables);
    }

    @Nullable
    public <T> T postForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
//        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
//        HttpEntity<MultiValueMap<String, String>> postEntity = getJsonHttpEntity(request, headers);
        return super.postForObject(url, postEntity, responseType, map);
    }

    @Nullable
    public <T> T postForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForObject(url, postEntity, responseType);
    }

    public <T> ResponseEntity<T> postForEntityWithHeader(String url, Map<String, String> headerMap, @Nullable Object request,
                                                         Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForEntity(url, postEntity, responseType, uriVariables);
    }

    public <T> ResponseEntity<T> postForEntityWithHeader(String url, Map<String, String> headerMap, @Nullable Object request,
                                                         Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForEntity(url, postEntity, responseType, map);
    }

    public <T> ResponseEntity<T> postForEntityWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForEntity(url, postEntity, responseType);
    }


    // ==========PUT========================================
    public void putWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        super.put(url, postEntity, uriVariables);
    }

    public void putWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        super.put(url, postEntity, map);
    }

    public void putWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        super.put(url, postEntity);
    }


    public String putWithHeaderAndResponse(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        ResponseEntity<String> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, String.class, uriVariables);
        return responseEntity.getBody();
    }

    public String putWithHeaderAndResponse(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        ResponseEntity<String> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, String.class, map);
        return responseEntity.getBody();
    }

    public String putWithHeaderAndResponse(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
//        return exchange(url, HttpMethod.PUT, request, String.class);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        ResponseEntity<String> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, String.class);
        return responseEntity.getBody();
    }

    public Map<String, Object> putWithHeaderAndMapResponse(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
//        return exchange(url, HttpMethod.PUT, request, Map.class, uriVariables);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        ResponseEntity<Map> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, Map.class, uriVariables);
        return responseEntity.getBody();
    }

    public Map<String, Object> putWithHeaderAndMapResponse(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        return exchange(url, HttpMethod.PUT, request, Map.class, map);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        ResponseEntity<Map> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, Map.class, map);
        return responseEntity.getBody();
    }

    public Map<String, Object> putWithHeaderAndMapResponse(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
//        return exchange(url, HttpMethod.PUT, request, Map.class);
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        ResponseEntity<Map> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, Map.class);
        return responseEntity.getBody();
    }


    // ==============PATCH==========================================

    @Nullable
    public <T> T patchForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.patchForObject(url, postEntity, responseType, uriVariables);
    }

    @Nullable
    public <T> T patchForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType,
                                          Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.patchForObject(url, postEntity, responseType, map);
    }

    @Nullable
    public <T> T patchForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.patchForObject(url, postEntity, responseType);
    }

    //==============以下为去掉class参数的重载==============

    //====get===========================================================================
    @Nullable
    public String getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        return getForObjectWithHeader(url, headerMap, paramMap, String.class, uriVariables);
    }

    @Nullable
    public String getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return getForObjectWithHeader(url, headerMap, paramMap, String.class, map);
    }

    @Nullable
    public Map<String, Object> getForMapWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        return getForObjectWithHeader(url, headerMap, paramMap, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> getForMapWithHeader(String url, Map<String, String> headerMap) throws RestClientException {
        return getForMapWithHeader(url, headerMap, new HashMap<>(), Map.class, new Object());
    }

    @Nullable
    public Map<String, Object> getForMapWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return getForObjectWithHeader(url, headerMap, paramMap, Map.class, map);
    }

    @Nullable
    public List<Map<String, Object>> getForListWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
        return getForObjectWithHeader(url, headerMap, paramMap, List.class, uriVariables);
    }

    @Nullable
    public List<Map<String, Object>> getForListWithHeader(String url, Map<String, String> headerMap) throws RestClientException {
        return getForListWithHeader(url, headerMap, new HashMap<>(), List.class, new Object());
    }

    @Nullable
    public List<Map<String, Object>> getForListWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return getForObjectWithHeader(url, headerMap, paramMap, List.class, map);
    }

//    @Nullable
//    public <T> T getForObject(URI url,Map<String,Object> paramMap, Class<T> responseType) throws RestClientException {
//        return super.getForObject(url, responseType);
//    }


    //=======post==========
    @Nullable
    public String postForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request,
                                          Object... uriVariables) throws RestClientException {
        return postForObjectWithHeader(url, headerMap, request, String.class, uriVariables);
    }

    @Nullable
    public String postForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postForObjectWithHeader(url, headerMap, request, String.class, map);
    }

    @Nullable
    public String postForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return postForObjectWithHeader(url, headerMap, request, String.class);
    }

    @Nullable
    public Map<String, Object> postForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return postForObjectWithHeader(url, headerMap, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> postForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postForObjectWithHeader(url, headerMap, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> postForMapWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return postForObjectWithHeader(url, headerMap, request, Map.class);
    }


    // ==============PATCH==========================================
    @Nullable
    public String patchForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchForObjectWithHeader(url, headerMap, request, String.class, uriVariables);
    }

    @Nullable
    public String patchForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchForObjectWithHeader(url, headerMap, request, String.class, map);
    }

    @Nullable
    public String patchForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return patchForObjectWithHeader(url, headerMap, request, String.class);
    }

    @Nullable
    public Map<String, Object> patchForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchForObjectWithHeader(url, headerMap, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> patchForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchForObjectWithHeader(url, headerMap, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> patchForMapWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return patchForObjectWithHeader(url, headerMap, request, Map.class);
    }


    //////======================================================================================================
    //////=====================                                                           ======================
    //////=====================            以上为携带header的请求                       ======================
    //////=====================                                                           ======================
    //////======================================================================================================


    //////======================================================================================================
    //////=====================                                                           ======================
    //////=====================  以下的方法名，均会携带Form字样，表示都是以form表单形式发起请求  ======================
    //////=====================                                                           ======================
    //////======================================================================================================

    //====get===========================================================================
//    @Nullable
//    public <T> T getForObject(String url, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
//        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
//    }

//    @Nullable
//    public <T> T getForObject(String url, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, map);
//    }

//    @Nullable
//    public <T> T getForObject(URI url,Map<String,Object> paramMap, Class<T> responseType) throws RestClientException {
//        return super.getForObject(url, responseType);
//    }

//    public <T> ResponseEntity<T> getForEntity(String url, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables)
//            throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
//        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
//    }

//    public <T> ResponseEntity<T> getForEntity(String url, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables)
//            throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, map);
//    }

//    @Override
//    public <T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException {
//        return super.getForEntity(url, responseType);
//    }


    // ============DELETE======================
//    public void delete(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        super.delete(ServletUtil.addParamter(url, paramMap), uriVariables);
//    }
//
//    public void delete(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        super.delete(ServletUtil.addParamter(url, paramMap), map);
//    }
//
//    public String deleteWithResponse(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, String.class, uriVariables);
//    }
//
//    public Map<String, Object> deleteWithMapResponse(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, uriVariables);
//    }
//
//    public String deleteWithResponse(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, String.class, map);
//    }
//
//    public Map<String, Object> deleteWithMapResponse(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return jsonExchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, map);
//    }

//    @Override
//    public void delete(URI url) throws RestClientException {
//        super.delete(url);
//    }

    //=====post=============================================================================
    @Nullable
    public URI postFormForLocation(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForLocation(url, formHttpEntity, uriVariables);
    }

    @Nullable
    public URI postFormForLocation(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForLocation(url, formHttpEntity, map);
    }

    @Nullable
    public URI postFormForLocation(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForLocation(url, formHttpEntity);
    }

    @Nullable
    public <T> T postFormForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForObject(url, formHttpEntity, responseType, uriVariables);
    }

    @Nullable
    public <T> T postFormForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForObject(url, formHttpEntity, responseType, map);
    }

    @Nullable
    public <T> T postFormForObject(URI url, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForObject(url, request, responseType);
    }

    public <T> ResponseEntity<T> postFormForEntity(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForEntity(url, formHttpEntity, responseType, uriVariables);
    }

    public <T> ResponseEntity<T> postFormForEntity(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForEntity(url, formHttpEntity, responseType, map);
    }

    public <T> ResponseEntity<T> postFormForEntity(URI url, @Nullable Object request, Class<T> responseType) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.postForEntity(url, formHttpEntity, responseType);
    }


    // ==========PUT========================================

    public void putForm(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        super.put(url, formHttpEntity, uriVariables);
    }

    public void putForm(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        super.put(url, formHttpEntity, map);
    }

    public void putForm(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        super.put(url, request);
    }

    public String putFormWithResponse(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return exchange(url, HttpMethod.PUT, formHttpEntity, String.class, uriVariables).getBody();

//        HttpEntity<Object> entity = getHttpEntity(request);
//        ResponseEntity<String> resultEntity = super.exchange(url,  HttpMethod.PUT, entity,  String.class, uriVariables);
//        return resultEntity.getBody();
    }

    public String putFormWithResponse(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return exchange(url, HttpMethod.PUT, formHttpEntity, String.class, map).getBody();
    }

    public String putFormWithResponse(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return exchange(url, HttpMethod.PUT, formHttpEntity, String.class).getBody();
    }

    public Map<String, Object> putFormWithMapResponse(String url, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return exchange(url, HttpMethod.PUT, formHttpEntity, Map.class, uriVariables).getBody();
    }

    public Map<String, Object> putFormWithMapResponse(String url, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return exchange(url, HttpMethod.PUT, formHttpEntity, Map.class, map).getBody();
    }

    public Map<String, Object> putFormWithMapResponse(URI url, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return exchange(url, HttpMethod.PUT, formHttpEntity, Map.class).getBody();
    }

    // ==============PATCH==========================================

    @Nullable
    public <T> T patchFormForObject(String url, @Nullable Object request, Class<T> responseType,
                                    Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.patchForObject(url, formHttpEntity, responseType, uriVariables);
    }

    @Nullable
    public <T> T patchFormForObject(String url, @Nullable Object request, Class<T> responseType,
                                    Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.patchForObject(url, formHttpEntity, responseType, map);
    }

    @Nullable
    public <T> T patchFormForObject(URI url, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpEntity<MultiValueMap<String, String>> formHttpEntity = getFormHttpEntity(request);
        return super.patchForObject(url, formHttpEntity, responseType);
    }

    //==============以下为去掉class参数的重载==============

//    //====get===========================================================================
//    @Nullable
//    public String getForObject(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        return getForObject(url, paramMap, String.class, uriVariables);
//    }
//
//    @Nullable
//    public String getForObject(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return getForObject(url, paramMap, String.class, map);
//    }
//
//    @Nullable
//    public Map<String, Object> getForMap(String url, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        return getForObject(url, paramMap, Map.class, uriVariables);
//    }
//
//    @Nullable
//    public Map<String, Object> getForMap(String url, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return getForObject(url, paramMap, Map.class, map);
//    }

//    @Nullable
//    public <T> T getForObject(URI url,Map<String,Object> paramMap, Class<T> responseType) throws RestClientException {
//        return super.getForObject(url, responseType);
//    }


    //=======post==========
    @Nullable
    public String postFormForObject(String url, @Nullable Object request,
                                    Object... uriVariables) throws RestClientException {
        return postFormForObject(url, request, String.class, uriVariables);
    }

    @Nullable
    public String postFormForObject(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postFormForObject(url, request, String.class, map);
    }

    @Nullable
    public String postFormForObject(URI url, @Nullable Object request) throws RestClientException {
        return postFormForObject(url, request, String.class);
    }

    @Nullable
    public Map<String, Object> postFormForMap(String url, @Nullable Object request,
                                              Object... uriVariables) throws RestClientException {
        return postFormForObject(url, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> postFormForMap(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postFormForObject(url, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> postFormForMap(URI url, @Nullable Object request) throws RestClientException {
        return postFormForObject(url, request, Map.class);
    }


    // ==============PATCH==========================================

    @Nullable
    public String patchFormForObject(String url, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchFormForObject(url, request, String.class, uriVariables);
    }

    @Nullable
    public String patchFormForObject(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchFormForObject(url, request, String.class, map);
    }

    @Nullable
    public String patchFormForObject(URI url, @Nullable Object request) throws RestClientException {
        return patchFormForObject(url, request, String.class);
    }

    @Nullable
    public Map<String, Object> patchFormForMap(String url, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchFormForObject(url, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> patchFormForMap(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchFormForObject(url, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> patchFormForMap(URI url, @Nullable Object request) throws RestClientException {
        return patchFormForObject(url, request, Map.class);
    }


    //////======================================================================================================
    //////=====================                                                           ======================
    //////=====================            以上为不携带header的请求                       ======================
    //////=====================            以下为携带header的请求                       ======================
    //////=====================                                                           ======================
    //////======================================================================================================

//
//    //====get===========================================================================
//    @Nullable
//    public <T> T getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
////        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
//
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType);
//        return responseEntity.getBody();
//    }
//
//    @Nullable
//    public <T> T getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
////        return super.getForObject(ServletUtil.addParamter(url, paramMap), responseType, map);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType, map);
//        return responseEntity.getBody();
//    }
//
//
//    public <T> ResponseEntity<T> getForEntityWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables)
//            throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
////        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, uriVariables);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        return super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType, uriVariables);
//    }
//
//    public <T> ResponseEntity<T> getForEntityWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables)
//            throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        //是刷token的标志为参数中有refreshToken参数
//        if (!CollectionUtils.isEmpty(paramMap) && null != paramMap.get(refreshTokenMapKey)) {
//            request1.setAttribute(refreshTokenParamMapKey, paramMap);
//        } else {
//            request1.setAttribute(paramMapKey, paramMap);
//        }
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
////        return super.getForEntity(ServletUtil.addParamter(url, paramMap), responseType, map);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        return super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.GET, httpEntity, responseType, map);
//    }
//
//
//    // ============DELETE======================
//    public <T> T deleteWithHeaderAndResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
////        super.delete(ServletUtil.addParamter(url, paramMap), uriVariables);
//
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, responseType, uriVariables);
//        return responseEntity.getBody();
//    }
//
//    public <T> T deleteWithHeaderAndResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
////        super.delete(ServletUtil.addParamter(url, paramMap), map);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<T> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, responseType, map);
//        return responseEntity.getBody();
//    }
//
//    public Map<String, Object> deleteWithHeaderAndMapResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
////        return exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, uriVariables);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<Map> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, Map.class, uriVariables);
//        return responseEntity.getBody();
//    }
//
//    public String deleteWithHeaderAndResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
////        return exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, String.class, map);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<String> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, String.class, map);
//        return responseEntity.getBody();
//    }
//
//    public Map<String, Object> deleteWithHeaderAndMapResponse(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        request1.setAttribute(paramMapKey, paramMap);
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
////        return exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, paramMap, Map.class, map);
//        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
//        ResponseEntity<Map> responseEntity = super.exchange(ServletUtil.addParamter(url, paramMap), HttpMethod.DELETE, httpEntity, Map.class, map);
//        return responseEntity.getBody();
//    }

//    @Override
//    public void delete(URI url) throws RestClientException {
//        super.delete(url);
//    }

    //=====post=============================================================================
    @Nullable
    public URI postFormForLocationWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForLocation(url, postEntity, uriVariables);
    }

    @Nullable
    public URI postFormForLocationWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForLocation(url, postEntity, map);
    }

    @Nullable
    public URI postFormForLocationWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.postForLocation(url, postEntity);
    }

    @Nullable
    public <T> T postFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }

        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.postForObject(url, postEntity, responseType, uriVariables);
    }

    @Nullable
    public <T> T postFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
//        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
//        HttpEntity<MultiValueMap<String, String>> postEntity = getJsonHttpEntity(request, headers);
        return super.postForObject(url, postEntity, responseType, map);
    }

    @Nullable
    public <T> T postFormForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.postForObject(url, postEntity, responseType);
    }

    public <T> ResponseEntity<T> postFormForEntityWithHeader(String url, Map<String, String> headerMap, @Nullable Object request,
                                                             Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.postForEntity(url, postEntity, responseType, uriVariables);
    }

    public <T> ResponseEntity<T> postFormForEntityWithHeader(String url, Map<String, String> headerMap, @Nullable Object request,
                                                             Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.postForEntity(url, postEntity, responseType, map);
    }

    public <T> ResponseEntity<T> postFormForEntityWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        return super.postForEntity(url, postEntity, responseType);
    }


    // ==========PUT========================================
    public void putFormWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        super.put(url, postEntity, uriVariables);
    }

    public void putFormWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        super.put(url, postEntity, map);
    }

    public void putFormWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        super.put(url, postEntity);
    }


    public String putFormWithHeaderAndResponse(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        ResponseEntity<String> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, String.class, uriVariables);
        return responseEntity.getBody();
    }

    public String putFormWithHeaderAndResponse(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (request1 != null) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        ResponseEntity<String> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, String.class, map);
        return responseEntity.getBody();
    }

    public String putFormWithHeaderAndResponse(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (request1 != null) {
            request1.setAttribute(paramMapKey, request);
        }
//        return exchange(url, HttpMethod.PUT, request, String.class);
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        ResponseEntity<String> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, String.class);
        return responseEntity.getBody();
    }

    public Map<String, Object> putFormWithHeaderAndMapResponse(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (request1 != null) {
            request1.setAttribute(paramMapKey, request);
        }
//        return exchange(url, HttpMethod.PUT, request, Map.class, uriVariables);
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        ResponseEntity<Map> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, Map.class, uriVariables);
        return responseEntity.getBody();
    }

    public Map<String, Object> putFormWithHeaderAndMapResponse(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (request1 != null) {
            request1.setAttribute(paramMapKey, request);
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
//        return exchange(url, HttpMethod.PUT, request, Map.class, map);
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        ResponseEntity<Map> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, Map.class, map);
        return responseEntity.getBody();
    }

    public Map<String, Object> putFormWithHeaderAndMapResponse(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (request1 != null) {
            request1.setAttribute(paramMapKey, request);
        }
//        return exchange(url, HttpMethod.PUT, request, Map.class);
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        ResponseEntity<Map> responseEntity = super.exchange(url, HttpMethod.PUT, postEntity, Map.class);
        return responseEntity.getBody();
    }


    // ==============PATCH==========================================

    @Nullable
    public <T> T patchFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (request1 != null) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.patchForObject(url, postEntity, responseType, uriVariables);
    }

    @Nullable
    public <T> T patchFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType,
                                              Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        request1.setAttribute(paramMapKey, request);
        Map<String, Object> map = null;
        if (request1 != null) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.patchForObject(url, postEntity, responseType, map);
    }

    @Nullable
    public <T> T patchFormForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request, Class<T> responseType)
            throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        if (null != request1) {
            request1.setAttribute(paramMapKey, request);
        }
        HttpHeaders headers = getHttpHeaders(headerMap);
//        HttpEntity<Object> postEntity = new HttpEntity<>(request, headers);
        HttpEntity<MultiValueMap<String, String>> postEntity = getFormHttpEntity(request, headers);
        return super.patchForObject(url, postEntity, responseType);
    }

    //==============以下为去掉class参数的重载==============

//    //====get===========================================================================
//    @Nullable
//    public String getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        return getForObjectWithHeader(url, headerMap, paramMap, String.class, uriVariables);
//    }
//
//    @Nullable
//    public String getForObjectWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return getForObjectWithHeader(url, headerMap, paramMap, String.class, map);
//    }
//
//    @Nullable
//    public Map<String, Object> getForMapWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Object... uriVariables) throws RestClientException {
//        return getForObjectWithHeader(url, headerMap, paramMap, Map.class, uriVariables);
//    }
//
//    @Nullable
//    public Map<String, Object> getForMapWithHeader(String url, Map<String, String> headerMap, Map<String, Object> paramMap, Map<String, ?> uriVariables) throws RestClientException {
//        HttpServletRequest request1 = RequestContext.getRequest();
//        Map<String, Object> map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
//        if (!CollectionUtils.isEmpty(uriVariables)) {
//            map.putAll(uriVariables);
//        }
//        return getForObjectWithHeader(url, headerMap, paramMap, Map.class, map);
//    }

//    @Nullable
//    public <T> T getForObject(URI url,Map<String,Object> paramMap, Class<T> responseType) throws RestClientException {
//        return super.getForObject(url, responseType);
//    }


    //=======post==========
    @Nullable
    public String postFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request,
                                              Object... uriVariables) throws RestClientException {
        return postFormForObjectWithHeader(url, headerMap, request, String.class, uriVariables);
    }

    @Nullable
    public String postFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (request1 != null) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postFormForObjectWithHeader(url, headerMap, request, String.class, map);
    }

    @Nullable
    public String postFormForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return postFormForObjectWithHeader(url, headerMap, request, String.class);
    }

    @Nullable
    public Map<String, Object> postFormForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return postFormForObjectWithHeader(url, headerMap, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> postFormForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (request1 != null) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return postFormForObjectWithHeader(url, headerMap, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> postFormForMapWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return postFormForObjectWithHeader(url, headerMap, request, Map.class);
    }


    // ==============PATCH==========================================
    @Nullable
    public String patchFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchFormForObjectWithHeader(url, headerMap, request, String.class, uriVariables);
    }

    @Nullable
    public String patchFormForObjectWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (request1 != null) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchFormForObjectWithHeader(url, headerMap, request, String.class, map);
    }

    @Nullable
    public String patchFormForObjectWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return patchFormForObjectWithHeader(url, headerMap, request, String.class);
    }

    @Nullable
    public Map<String, Object> patchFormForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Object... uriVariables) throws RestClientException {
        return patchFormForObjectWithHeader(url, headerMap, request, Map.class, uriVariables);
    }

    @Nullable
    public Map<String, Object> patchFormForMapWithHeader(String url, Map<String, String> headerMap, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException {
        HttpServletRequest request1 = RequestContext.getRequest();
        Map<String, Object> map = null;
        if (request1 != null) {
            map = (Map<String, Object>) request1.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        }
        if (!CollectionUtils.isEmpty(uriVariables)) {
            map = map == null ? new HashMap<>() : map;
            map.putAll(uriVariables);
        }
        return patchFormForObjectWithHeader(url, headerMap, request, Map.class, map);
    }

    @Nullable
    public Map<String, Object> patchFormForMapWithHeader(URI url, Map<String, String> headerMap, @Nullable Object request) throws RestClientException {
        return patchFormForObjectWithHeader(url, headerMap, request, Map.class);
    }


    //////======================================================================================================
    //////=====================                                                           ======================
    //////=====================            以上为携带header的form请求                       ======================
    //////=====================                                                           ======================
    //////======================================================================================================

}
